#ifndef _LOG_H_
#define _LOG_H_

#ifdef __cplusplus
extern "C" {
#endif

#define LOG_BUF_SIZE 1024

typedef unsigned int (*get_sys_time_ms_def)(void);

enum log_color
{
    NULL_COLOR  = 0,
    DEBUG_COLOR	= 1,
    INFO_COLOR  = 2,
    WARN_COLOR	= 3,
    ERROR_COLOR	= 4
};

#define CSI_START                      "\033["
#define CSI_END                        "\033[0m"
/* output log front color */
#define F_BLACK                        "30;"
#define F_RED                          "31;"
#define F_GREEN                        "32;"
#define F_YELLOW                       "33;"
#define F_BLUE                         "34;"
#define F_MAGENTA                      "35;"
#define F_CYAN                         "36;"
#define F_WHITE                        "37;"
/* output log background color */
#define B_NULL
#define B_BLACK                        "40;"
#define B_RED                          "41;"
#define B_GREEN                        "42;"
#define B_YELLOW                       "43;"
#define B_BLUE                         "44;"
#define B_MAGENTA                      "45;"
#define B_CYAN                         "46;"
#define B_WHITE                        "47;"
/* output log fonts style */
#define S_BOLD                         "1m"
#define S_UNDERLINE                    "4m"
#define S_BLINK                        "5m"
#define S_NORMAL                       "22m"

#define LOG_COLOR_ERROR                         (F_RED B_NULL S_NORMAL)
#define LOG_COLOR_WARN                          (F_YELLOW B_NULL S_NORMAL)
#define LOG_COLOR_INFO                          (F_CYAN B_NULL S_NORMAL)
#define LOG_COLOR_DEBUG                         (F_GREEN B_NULL S_NORMAL)

#define LOG_TAIL_CHAR					"\n"

void log_print(enum log_color color, const char *file, int line, const char *func, const char* fmt, ...);
void log_time_register(get_sys_time_ms_def p_get_sys_time_ms);
void log_dump_hex(const char *title_str, const unsigned char *buf, unsigned int size, unsigned int number);


#define LOG_LVL_ERROR                       1
#define LOG_LVL_WARN                        2
#define LOG_LVL_INFO                        3
#define LOG_LVL_DEBUG                       4

#ifndef LOG_LVL
    #define LOG_LVL          LOG_LVL_DEBUG
#endif

#if LOG_LVL >= LOG_LVL_DEBUG
	/* 添加函数名可以使用*/
//	#define log_d(...) log_print(DEBUG_COLOR, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
	#define log_d(...) log_print(DEBUG_COLOR, __FILE__, __LINE__, "",__VA_ARGS__)
#else
    #define log_d(...)       ((void)0)
#endif

#if LOG_LVL >= LOG_LVL_INFO
	#define log_i(...) log_print(INFO_COLOR, __FILE__, __LINE__, "",__VA_ARGS__)
#else
    #define log_i(...)       ((void)0)
#endif

#if LOG_LVL >= LOG_LVL_WARN
	#define log_w(...) log_print(WARN_COLOR, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
    #define log_w(...)       ((void)0)
#endif

#if LOG_LVL >= LOG_LVL_ERROR
	#define log_e(...) log_print(ERROR_COLOR, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
    #define log_e(...)       ((void)0)
#endif




#ifdef __cplusplus
}
#endif

#endif
